Let's trace the relationships for the node with value 19 at index 1.
- Parent:
floor((1 - 1) / 2)=floor(0)= index0. The parent is100. Correct. - Left Child:
2 * 1 + 1= index3. The left child is17. Correct. - Right Child:
2 * 1 + 2= index4. The right child is3. Correct.
# Array representation of the Max-Heap
heap = [100, 19, 36, 17, 3, 25, 1]
# Let's find relationships for index i = 1 (value 19)
i = 1
parent_i = (i - 1) // 2 # floor division
left_child_i = 2 * i + 1
right_child_i = 2 * i + 2
# heap[parent_i] is 100
# heap[left_child_i] is 17
# heap[right_child_i] is 3